<?php

class Web_Admin_Categorias_ModificarSubcategoria extends Web_Admin_MainPage
{
    
    public function mainContent()
    {
        return $this->actualizar();
    }
    
    private function actualizar()
    {
        if (isset($_SESSION['error'])) {
            $error = $_SESSION['error'];
            unset($_SESSION['error']);
        }
        
        $sub_id = Ey::getPrm(3);
        $obj = new Web_Db_Categorias();
        $rs = $obj->fetchRow($obj->select()
                                ->where('cat_id=?', $sub_id));
        
        $sub = array('id' => $rs->cat_id,
                    'nombre' => $rs->cat_nombre);
        
        $cats = $obj->fetchAll($obj->select()
                                ->order('cat_nombre')
                                ->where('cat_padre_id=?', 0));
        
        $html = '';
        foreach ($cats as $cat) {
            if ($rs->cat_padre_id == $cat->cat_id) {
                $html.='<option selected="selected" value="' . $cat->cat_id . '">' . $cat->cat_nombre . '</option>';
            } else {
                $html.='<option value="' . $cat->cat_id . '">' . $cat->cat_nombre . '</option>';
            }
        }
        
        $smarty = new Smarty_Engine();
        $smarty->assign('error', $error);
        $smarty->assign('sub', $sub);
        $smarty->assign('html', $html);
        
        return $smarty->fetch(ADMIN_CATEGORIAS_DIR . DS . 'tpl' . DS . 'modificar-subcategoria.tpl');
    }

}